<%@taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@taglib uri="/WEB-INF/struts-bean.tld" prefix="bean"%>
<%@taglib uri="http://java.sun.com/jstl/core_rt" prefix="c" %>
<%@taglib uri="http://java.fckeditor.net" prefix="FCK" %>

<div>
    <logic:present name="acc">
        <p align="right">
            <a href="AdminTour.do?action=listTour" >Tour manager</a>&emsp;&emsp;&emsp;
            <a href="AdminTour.do?action=listTourServices" >Tour Service manager</a> &emsp;&emsp;&emsp;
            <a href="AdminTour.do?action=listTourType" >Tour Type manager</a> &emsp;&emsp;&emsp;
            <a href="AdminTour.do?action=listTourLocation" >Location manager</a>
        </p>
        <form action="insertTour.do" method="post" enctype="multipart/form-data">
            <table class="tablemain" border="0">
                <tr >
                    <th height="32" colspan="3" scope="col" bgcolor="#A6A8B1"><b>Add New Tour</b> </th>
                </tr>
                <tr>
                    <td height="15"><div align="right"><font size="2">Tour Name :</font> </div></td>
                    <td colspan="2"><input type="text" name="tourName" id="name" /></td>
                </tr>
                <tr>
                    <td height="39"><div align="right"><font size="2">Introduction :</font> </div></td>
                    <td colspan="2">
                        <FCK:editor instanceName="intro" width="100%" height="200">
                        </FCK:editor>
                    </td>
                </tr>
                <tr>
                    <td height="15" colspan="0"><div align="right"><font size="2">Images :</font> </div></td>
                    <td>  <input name="images" type="file" id="img"> <input type="button" value="new service" onClick="loadXMLDoc('newser','AdminTour.do?action=listTourService')"></td>
                   
                </tr>
                <tr>
                    <td colspan="2" align="center"><div id="newser"></div></td>
                </tr>
                <tr>
                    <td ><div align="right"><font size="2">Tour Service :</font> </div></td>
                    <td><fieldset  style="color:black;"><legend><b><font size="2">Service</font> </b></legend>
                           <font size="2"> Service :</font>  <select name="service" id="service">
                                <logic:present name="listService">
                                    <logic:iterate name="listService" id="listService">
                                        <option value="<bean:write name="listService" property="tourServiceId"/>">
                                            <bean:write name="listService" property="tourServiceName"/>
                                        </option>
                                    </logic:iterate>
                                </logic:present>
                            </select><br>
                            <font size="2">Detail  :</font> <textarea rows="5" cols="40" name="detail"></textarea><br>
                            <font size="2"> Price    :</font><input type="text" name="priceser">
                        </fieldset>
                    </td>
                </tr>
                  <tr>
                    <td><div align="right"><font size="2">Price :</font> </div></td>
                    <td>
                        <fieldset  style="color:black;"><legend><b><font size="2"> Price Table</font></b></legend>
                            <font size="2">1px :</font>  <input type="text" name="onep"><br>
                            <font size="2">2-3px :</font>  <input type="text" name="twop"><br>
                            <font size="2">4-6 px :</font>  <input type="text" name="forp"><br>
                            <font size="2">7 px : </font> <input type="text" name="overp">
                        </fieldset>
                    </td>
                </tr>

                 <tr>
                    <td><div align="right"><font size="2">Tour Type</font> </div></td>
                    <td>
                        <fieldset  style="color:black;"><legend><b><font size="2"> Tour Type Table</font></b></legend>
                            <font size="2"> Tour Type :</font><select name="tourType">
                                <logic:present name="listTourType">
                                    <logic:iterate name="listTourType" id="listTourType">
                                        <option value="<bean:write name="listTourType" property="tourTypeId"/>">
                                            <bean:write name="listTourType" property="tourTypeName"/>
                                        </option>
                                    </logic:iterate>
                                </logic:present>
                            </select><br>
                            <font size="2">Departure :</font>  <input type="text" name="Departure" id="qty" /><br>
                            <font size="2"> Destination :</font> <input type="text" name="Destination" id="qty" /><br>
                            <font size="2">Duration :</font>  <input type="text" name="Duration" id="quantity" />
                        </fieldset>
                    </td>
                </tr>

                <tr>
                    <td><div align="right"><font size="2">Schedules</font> </div></td>
                    <td>
                        <fieldset  style="color:black;"><legend><b><font size="2">Schedules Table</font> </b></legend>
                           <font size="2">Schedules :</font>   <input type="button" value="new Schedules" onClick="loadXMLDoc('newlocal','AdminTour.do?action=listLocaltion')"><br>
                           <font size="2"> Location : </font>  <select name="localtion">
                                <logic:present name="listLocaltion">
                                    <logic:iterate name="listLocaltion" id="listLocaltion">
                                        <option value="<bean:write name="listLocaltion" property="locationId"/>">
                                            <bean:write name="listLocaltion" property="locationName"/>
                                        </option>
                                    </logic:iterate>
                                </logic:present>
                            </select><br>
                           <font size="2"> Description :</font>  <textarea name="desSche" cols="100" rows="5"></textarea><br>

                        </fieldset>
                    </td>
                </tr>
                <tr>
                    <td colspan="2">
                        <div id="newlocal"></div>
                    </td>
                </tr>
                <tr>
                    <td colspan="2" align="center"><input type="submit" name="action" value="InsertTour" /></td>
                </tr>
            </table>
                 

        </form>
    </logic:present>
    <logic:notPresent name="acc">
        <jsp:forward page="adminHome.jsp"/>
    </logic:notPresent>
</div>
<script language="JavaScript">
    function addnew(){
        document.getElementById("image").innerHTML += "<input name='images' type='file' id='img'> <br/>";
    }
    //check image
    function checkimg(element,helperMsg){
        if(element.value == "No file chosen"){
            alert(helperMsg);
            elem.focus(); // set the focus to this input
            return false;
        }
        return true;
    }
    // If the length of the element's string is 0 then display helper message
    function notEmpty(elem, helperMsg){
        if(elem.value.length == 0){
            alert(helperMsg);
            elem.focus(); // set the focus to this input
            return false;
        }
        return true;
    }
    // If the element's string matches the regular expression it is all numbers
    function isNumeric(elem, helperMsg){
        var numericExpression = /^[0-9]+$/;
        if(elem.value.match(numericExpression)){
            return true;
        }else{
            alert(helperMsg);
            elem.focus();
            return false;
        }
    }
    function formValidator(){
        // Make quick references to our fields
        var carName = document.getElementById('name');
        var image = document.getElementById('image');
        var qty = document.getElementById('qty');
        var seat = document.getElementById('seat');
        var price = document.getElementById('price');

        // Check each input in the order that it appears in the form!
        if(notEmpty(carName, "Please enter car name")){
            if(checkimg(image, "Please choose images")){
                if(notEmpty(qty, "Please enter quantity")){
                    if(isNumeric(qty, "Quantity is number")){
                        if(notEmpty(seat, "Please enter seat quantity")){
                            if(isNumeric(seat,"seat quantity is number")){
                                if(notEmpty(price, "Please enter price")){
                                    if(isNumeric(price,"price is number")){

                                        return true;

                                    }

                                }
                            }
                        }
                    }
                }
            }
        }
        return false;
    }

    function loadXMLDoc(id,element)
    {
        if (window.XMLHttpRequest)
        {// code for IE7+, Firefox, Chrome, Opera, Safari
            xmlhttp=new XMLHttpRequest();
        }
        else
        {// code for IE6, IE5
            xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
        }
        xmlhttp.onreadystatechange=function()
        {
            if (xmlhttp.readyState==4 && xmlhttp.status==200)
            {
                document.getElementById(id).innerHTML+=xmlhttp.responseText;
            }
        }
        xmlhttp.open("GET",element,true);
        xmlhttp.send();
    }

</script>
